﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;
using ARR.Entities;
using ARR.DataModel.Repositories;

namespace ARR.Services.Domain.Exporters
{
    public static class ExportHelper
    {
        public static FileInfo CreateExcelFile(string fileName)
        {
            string outputDir = ConfigurationManager.AppSettings["ExportersPath"];

            FileInfo newFile = new FileInfo(Path.Combine(outputDir, fileName));
            if (newFile.Exists)
            {
                newFile.Delete();  // ensures we create a new workbook
                newFile = new FileInfo(Path.Combine(outputDir, fileName));
            }

            return newFile;
        }

        public static List<Article> GetArticlesToExport(RangeReview rangeReview)
        {
            var articleRows = ArticlesRepository.Select(art => art.RangeReviewId == rangeReview.Id);

            return articleRows.ToList().ConvertAll<Article>(row => new Article(row));
        }

        internal static List<TempStore> GetStoresToExport(Country country)
        {
            var storeRows = TempStoresRepository.Select(store => store.CountryId == country.Id);

            return storeRows.ToList().ConvertAll<TempStore>(row => new TempStore(row));
        }
    }
}
